import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_baidu_mapapi_base/flutter_baidu_mapapi_base.dart';
import 'package:flutter_baidu_mapapi_map/flutter_baidu_mapapi_map.dart';

class MapPage extends StatelessWidget {
  BMFMapController? myMapController;
  BMFMapType? mapType = BMFMapType.Standard;

  @override
  Widget build(BuildContext context) {
    return generateMap(context);
  }

  /// 创建地图
  Container generateMap(BuildContext context) {
    return Container(
      height: MediaQuery.of(context).size.height,
      width: MediaQuery.of(context).size.width,
      child: BMFMapWidget(
        onBMFMapCreated: (controller) {
          onBMFMapCreated(controller);
        },
        mapOptions: initMapOptions(),
      ),
    );
  }

  /// 设置地图参数
  BMFMapOptions initMapOptions() {
    BMFCoordinate center = BMFCoordinate(39.965, 116.404);
    BMFMapOptions mapOptions = BMFMapOptions(mapType: BMFMapType.Standard, zoomLevel: 12, maxZoomLevel: 21, minZoomLevel: 4, logoPosition: BMFLogoPosition.LeftBottom, mapPadding: BMFEdgeInsets(top: 0, left: 50, right: 50, bottom: 0), overlookEnabled: true, overlooking: -15, center: center);
    return mapOptions;
  }

  // 创建完成回调
  void onBMFMapCreated(BMFMapController controller) {
    myMapController = controller;

    /// 地图加载回调
    myMapController?.setMapDidLoadCallback(callback: () {
      print('mapDidLoad-地图加载完成');
    });
  }
}
